package com.huabo.audit.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.audit.oracle.entity.TblNbkzRiskEntity;
import com.huabo.audit.oracle.entity.TblNbsjBugEntity;
import com.huabo.audit.oracle.entity.TblNbsjRisktolerability;
import com.huabo.audit.oracle.vo.TblNbkzRiskVo;
import com.huabo.audit.oracle.vo.TblNbsjBugVo;
import com.huabo.audit.service.TblNbkzRiskService;
import com.huabo.audit.service.TblNbsjBugService;
import com.huabo.audit.util.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 相关问题汇总
 */
@RestController
@Slf4j
@Api(value = "相关问题汇总", tags = { "相关问题汇总接口" })
@RequestMapping(value = "/auditPS")
public class NbsjProblemSumController {
	
	@Resource
	public TblNbsjBugService tblNbsjBugService;
	
	@Resource
	public TblNbkzRiskService nbkzRiskService;


	/**
	 * 缺陷管理列表
	 */
	@GetMapping("/sjbb/defect_list")
	@ApiOperation(value = "缺陷管理列表")
	public JsonBean workReportList(HttpServletRequest request, TblNbsjBugVo tblNbsjBugVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "orgid", value = "组织部门id", required = false) @RequestParam(value = "orgid", required = false) Integer orgid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.bugPageList(token, pageNumber, pageSize,tblNbsjBugVo,orgid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 缺陷管理-新增与修改
	 */
	@RequestMapping(value = "/sjbb/defect_add", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷管理-新增与修改")
    public JsonBean defect_add(HttpServletRequest request,@ApiParam(name="bug",value="实体",required=true)TblNbsjBugEntity bug,
								   @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
								   @ApiParam(name="attids",value="附件id数组",required=false)String attids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.bugAdd(bug,token,attids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 缺陷管理-新增与修改-内规选择列表
	 */
	@GetMapping("/inner_common_qxwt")
	@ApiOperation(value = "缺陷管理-新增与修改-内规选择列表")
	public JsonBean inner_common_qxwt(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "bugid", value = "bugid", required = false) @RequestParam(value = "bugid", required = false) Integer bugid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.innerCommonQxwtList(token, pageNumber, pageSize,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 缺陷管理-新增与修改-外规选择列表
	 */
	@GetMapping("/outer_common_qxwt")
	@ApiOperation(value = "缺陷管理-新增与修改-外规选择列表")
	public JsonBean outer_common_qxwt(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "bugid", value = "bugid", required = false) @RequestParam(value = "bugid", required = false) Integer bugid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.outerCommonQxwtList(token, pageNumber, pageSize,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 缺陷管理-新增与修改-选择内规保存
	 */
	@RequestMapping(value = "/qxwt/add_inner_qxwt", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷管理-新增与修改-选择内规保存")
    public JsonBean add_inner_qxwt(HttpServletRequest request,
								   @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
								   @ApiParam(name="bugid",value="bugid",required=false)Integer bugid,
								   @ApiParam(name="innrulids",value="内规ids",required=false)String innrulids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.bugInnrulidsAdd(token,bugid,innrulids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 缺陷管理-新增与修改-选择外规保存
	 */
	@RequestMapping(value = "/qxwt/add_outer_qxwt", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "缺陷管理-新增与修改-选择外规保存")
    public JsonBean add_outer_qxwt(HttpServletRequest request,
								   @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
								   @ApiParam(name="bugid",value="bugid",required=false)Integer bugid,
								   @ApiParam(name="outrulids",value="外规ids",required=false)String outrulids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.bugOutrulidsAdd(token,bugid,outrulids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 缺陷管理-关联内规查询
	 */
	@GetMapping("/inner_common_link")
	@ApiOperation(value = "缺陷管理-关联内规查询")
	public JsonBean inner_common_link(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "bugid", value = "bugid", required = false) @RequestParam(value = "bugid", required = false) Integer bugid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.innerCommonLinkList(token, 1, 99,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 缺陷管理-关联外规查询
	 */
	@GetMapping("/outer_common_link")
	@ApiOperation(value = "缺陷管理-关联外规查询")
	public JsonBean outer_common_link(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "bugid", value = "bugid", required = false) @RequestParam(value = "bugid", required = false) Integer bugid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.outerCommonLinkList(token, 1, 99,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	@GetMapping("/delete_qx_inner")
	@ApiOperation(value = "缺陷管理-关联内规-删除")
    public JsonBean delete_qx_inner(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="bugid",value="主键",required=true)@RequestParam(value = "bugid", required = true) Integer bugid,
    		@ApiParam(name="innrulids",value="内规ids",required=false)String innrulids) {
        
        try {
			return this.tblNbsjBugService.bugInnrulidsDelete(token,bugid,innrulids);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	@GetMapping("/delete_qx_outer")
	@ApiOperation(value = "缺陷管理-关联外规-删除")
    public JsonBean delete_qx_outer(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="bugid",value="主键",required=true)@RequestParam(value = "bugid", required = true) Integer bugid,
    		@ApiParam(name="outrulids",value="外规ids",required=false)String outrulids) {
        
        try {
			return this.tblNbsjBugService.bugOutrulidsDelete(token,bugid,outrulids);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	
	/**
	 * 缺陷管理-关联缺陷-选择保存
	 */
	@RequestMapping(value = "/qxwt/add_defect_qxwt", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "关联缺陷-选择保存")
    public JsonBean add_defect_qxwt(HttpServletRequest request,
								   @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
								   @ApiParam(name="bugid",value="bugid",required=false)Integer bugid,
								   @ApiParam(name="bugids",value="关联bugids",required=false)String bugids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.defectQxwtAdd(token,bugid,bugids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 缺陷管理-关联缺陷查询
	 */
	@GetMapping("/qxwt/defect_link")
	@ApiOperation(value = "缺陷管理-关联缺陷查询")
	public JsonBean defect_link(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "bugid", value = "bugid", required = false) @RequestParam(value = "bugid", required = false) Integer bugid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjBugService.defectLinkList(token, 1, 99,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 缺陷管理-关联缺陷删除
	 */
	@GetMapping("/delete_qx_child")
	@ApiOperation(value = "缺陷管理-关联缺陷删除")
    public JsonBean delete_qx_child(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="bugid",value="主键",required=true)@RequestParam(value = "bugid", required = true) Integer bugid,
    		@ApiParam(name="bugids",value="关联bugids",required=false)String bugids) {
        
        try {
			return this.tblNbsjBugService.bugFatherDelete(token,bugid,bugids);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	
	
	/**
	 * 缺陷管理-删除
	 */
	@GetMapping("/sjbb/defect_del")
	@ApiOperation(value = "缺陷管理-删除")
    public JsonBean workReportDelete(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="bugid",value="主键",required=true)@RequestParam(value = "bugid", required = true) Integer bugid) {
        
        try {
			return tblNbsjBugService.bugDelete(bugid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	/**
	 * 缺陷管理-明细
	 */
	@GetMapping("/sjbb/defect_detail")
    @ApiOperation(value = "缺陷管理-明细")
    public JsonBean workReportDetail(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="bugid",value="主键",required=true)@RequestParam(value = "bugid", required = true) Integer bugid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjBugService.findBugDetail(token,bugid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }

	/**
	 * 缺陷管理-附件列表
	 */
	@GetMapping("/sjbb/defect_file_list")
	@ApiOperation(value = "缺陷管理-附件列表")
	public JsonBean defect_file_list(HttpServletRequest request,
											 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
											 @ApiParam(name = "bugId", value = "业务主键", required = true) @RequestParam(value = "bugId", required = true) Integer bugId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.defectFileList(token,bugId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
     * 缺陷管理-附件删除
     */
    @GetMapping("/sjbb/defect_file_del")
    @ApiOperation(value = "缺陷管理-附件删除")
    public R defect_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.tblNbsjBugService.removeAttInfoByAttId(token, attId);
    }
	
	/**
	 * 缺陷管理-导出
	 */
	@GetMapping("/sjbb/defect_file_export")
	@ApiOperation(value = "缺陷管理-导出")
	public JsonBean defect_file_export(HttpServletRequest request, HttpServletResponse response,
										   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
										   @ApiParam(name="orgId",value="组织编号",required=false)@RequestParam(value = "orgId", required = false) Integer orgId) throws Exception {
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjBugService.defect_file_export(token, orgId,response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 缺陷管理-新增修改-获取缺陷级别
	 */
	@GetMapping("/sjbb/bug_criterion_list")
    @ApiOperation(value = "缺陷管理-明细")
    public JsonBean bug_criterion_list(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjBugService.findBugCriterion(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 风险发现列表
	 */
	@GetMapping("/wthz/risk_list")
	@ApiOperation(value = "风险发现列表")
	public JsonBean risk_list(HttpServletRequest request, TblNbkzRiskVo tblNbkzRiskVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "orgid", value = "组织部门id", required = false) @RequestParam(value = "orgid", required = false) Integer orgid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.nbkzRiskService.riskPageList(token, pageNumber, pageSize,tblNbkzRiskVo, orgid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 风险发现-新增与修改
	 */
	@RequestMapping(value = "/wthz/risk_add", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "风险发现-新增与修改")
    public JsonBean risk_add(HttpServletRequest request,@ApiParam(name="risk",value="实体",required=true)TblNbkzRiskEntity risk,
							 @ApiParam(name="attids",value="附件id数组",required=false)String attids,
							 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.nbkzRiskService.riskAdd(risk,token,attids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 风险发现-删除
	 */
	@GetMapping("/wthz/risk_del")
	@ApiOperation(value = "风险发现-删除")
    public JsonBean risk_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="riskid",value="主键",required=true)@RequestParam(value = "riskid", required = true) Integer riskid) {
        
        try {
			return this.nbkzRiskService.riskDelete(riskid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	/**
	 * 风险发现-明细
	 */
	@GetMapping("/wthz/risk_detail")
    @ApiOperation(value = "风险发现-明细")
    public JsonBean risk_detail(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="riskid",value="主键",required=true)@RequestParam(value = "riskid", required = true) Integer riskid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = this.nbkzRiskService.findRiskDetail(token,riskid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }

	/**
	 * 风险发现-附件列表
	 */
	@GetMapping("/wthz/risk_file_list")
	@ApiOperation(value = "风险发现-附件列表")
	public JsonBean risk_file_list(HttpServletRequest request,
									 @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
									 @ApiParam(name = "riskId", value = "业务主键", required = true) @RequestParam(value = "riskId", required = true) Integer riskId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.nbkzRiskService.risk_file_list(token,riskId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
     * 风险发现-附件删除
     */
    @GetMapping("/wthz/risk_file_del")
    @ApiOperation(value = "风险发现-附件删除")
    public R risk_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.nbkzRiskService.removeAttInfoByAttId(token, attId);
    }
	
	/**
	 * 风险发现-风险容忍度保存
	 */
	@RequestMapping(value = "/wthz/fxrrd_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "风险发现-风险容忍度保存")
    public JsonBean fxrrd_save(HttpServletRequest request,
								   @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
								   @ApiParam(name="tnr",value="",required=false)TblNbsjRisktolerability tnr)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.nbkzRiskService.fxrrdAdd(token,tnr);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 风险发现-风险容忍度删除
	 */
	@GetMapping("/wthz/fxrrd_del")
	@ApiOperation(value = "风险发现-风险容忍度删除")
    public JsonBean fxrrd_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="toleid",value="主键",required=true)@RequestParam(value = "toleid", required = true) Integer toleid) {
        
        try {
			return nbkzRiskService.fxrrdDelete(toleid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	/**
	 * 风险发现-风险容忍度查询
	 */
	@GetMapping("/wthz/fxrrd_list")
	@ApiOperation(value = "风险发现-风险容忍度查询")
	public JsonBean fxrrd_list(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "riskid", value = "riskid", required = false) @RequestParam(value = "riskid", required = false) Integer riskid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = nbkzRiskService.fxrrdLinkList(token, 1, 99,riskid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
}
